// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import layout from './layout'
import router from './router'
import VueResource from 'vue-resource'
import ElementUI from 'element-ui'
import { emoji } from './api/emoji.js'

Vue.prototype.emoji = emoji
require('font-awesome-webpack')
Vue.use(VueResource);
Vue.config.productionTip = false
var VueCookie = require('vue-cookie');
Vue.use(VueCookie);
Vue.use(ElementUI);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<layout/>',
  components: { layout }
})
router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
        if (VueCookie.get('uid') != '') {  // 通过vuex state获取当前的token是否存在
            next();
        }else {
            next({name:"index"});
        }
    }else {
        next();
    }
})